<template>
  <!-- 维护作业-保单打印险种维护页面 -->
  <div class="fillcontain">
    <el-form :model="searchParams" :rules="rules" ref="ruleForm" label-width="120px" class="search_container">
      <el-row>
        <el-col :span="6">
          <el-form-item label="EUIS险种代码" prop="polpln">
            <el-input clearable v-model="searchParams.polpln" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="AS400险种代码" prop="crtable">
            <el-input clearable v-model="searchParams.crtable" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </el-form>
    <div class="contain">
      <el-row class="bgfff pb15">
        <el-col :span="24" class="pt5">
          <el-button type="danger" plain @click="addData_F">新增</el-button>
        </el-col>
      </el-row>
      <!-- 主档显示结果 -->
      <div class="table_container">
        <el-table
            v-loading="loading_F"
            :data="insCodetableData"
            highlight-current-row
            @current-change="selectRow_F"
            @row-dblclick="viewRow_F"
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="120"
              property="polpln"
              label="EUIS险种代码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="crtable"
              label="AS400险种代码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="statFund"
              :formatter="statFundFormat"
              label="主约"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag01"
              :formatter="flag01Format"
              label="检测类型"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag02"
              :formatter="flag02Format"
              label="金额类型"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag03"
              :formatter="flag03Format"
              label="保单条款打印"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="140"
              property="flag04"
              :formatter="flag04Format"
              label="首页金额合并打印"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag05"
              :formatter="flag05Format"
              label="保额打印"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="srpisno"
              label="需求号码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="updateInd"
              :formatter="updateIndFormat"
              label="更新方式"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              fixed="right"
              label="操作"
              align='center'>
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small" @click.stop="editData_F(scope.row)">修改</el-button> -->
              <span class="operationIcon" @click.stop="editData_F(scope.row)">
                  <el-tooltip class="item" effect="light" content="修改" placement="top">
                   <i class="el-icon-edit"></i>
                  </el-tooltip>
                </span>

              <!-- <el-button type="text" size="small" @click.stop="deleteData_F(scope.row)">删除</el-button> -->
              <span class="operationIcon ml5" @click.stop="deleteData_F(scope.row)">
                  <el-tooltip class="item" effect="light" content="删除" placement="top">
                    <i class="el-icon-delete"></i>
                  </el-tooltip>
                </span>

            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination
                  background
                  v-if='paginations_F.total > 0'
                  :page-sizes="paginations_F.pageSizes"
                  :page-size="paginations_F.pageSize"
                  :layout="paginations_F.layout"
                  :total="paginations_F.total"
                  :current-page='paginations_F.pageIndex'
                  @current-change='handleCurrentChange_F'
                  @size-change='handleSizeChange_F'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 附档显示结果 -->
      <div class="table_container mt20" v-if="isShow_S">
        <el-row class="bgfff pb15">
          <el-col :span="24" class="pt5">
            <el-button type="danger" plain @click="addData_S">新增</el-button>
          </el-col>
        </el-row>
        <el-table
            v-loading="loading_S"
            :data="attachedtableData"
            highlight-current-row
            @row-dblclick="viewRow_S"
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="120"
              property="polpln"
              label="EUIS主合同"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="crtable"
              label="AS400险种代码"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="polplnc"
              label="EUIS产品码"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag03"
              :formatter="flag03Format_S"
              label="条款打印"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="srpisno"
              label="需求号码"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="updateInd"
              :formatter="updateIndFormat"
              label="更新方式"
              align='center'>
          </el-table-column>
          <el-table-column
              min-width="120"
              fixed="right"
              label="操作"
              align='center'>
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small" @click.stop="editData_S(scope.row)">修改</el-button> -->
              <span class="operationIcon" @click.stop="editData_S(scope.row)">
                  <el-tooltip class="item" effect="light" content="修改" placement="top">
                   <i class="el-icon-edit"></i>
                  </el-tooltip>
                </span>
              <!-- <el-button type="text" size="small" @click.stop="deleteData_S(scope.row)">删除</el-button> -->
              <span class="operationIcon ml5" @click.stop="deleteData_S(scope.row)">
                  <el-tooltip class="item" effect="light" content="删除" placement="top">
                    <i class="el-icon-delete"></i>
                  </el-tooltip>
                </span>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination
                  background
                  v-if='paginations_S.total > 0'
                  :page-sizes="paginations_S.pageSizes"
                  :page-size="paginations_S.pageSize"
                  :layout="paginations_S.layout"
                  :total="paginations_S.total"
                  :current-page='paginations_S.pageIndex'
                  @current-change='handleCurrentChange_S'
                  @size-change='handleSizeChange_S'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 弹框 主档修改-->
    <el-dialog
        :title="title_father"
        :visible.sync="mainDialog"
        width="60%"
        center>
      <el-form ref="form_F" :model="fatherData" :rules="rules_F" label-width="130px">
        <el-row :gutter="100">
          <el-col :span="12">
            <el-form-item label="EUIS险种代码" prop="polpln">
              <el-input v-model="fatherData.polpln" :readonly="currentOperation_F == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="AS400险种代码" prop="crtable">
              <el-input v-model="fatherData.crtable" :readonly="currentOperation_F == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主约" prop="statFund">
              <el-select v-model="fatherData.statFund" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in masterContract"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检测类型" prop="flag01">
              <el-select v-model="fatherData.flag01" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in assayType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="金额类型" prop="flag02">
              <el-select v-model="fatherData.flag02" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in amountType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保单条款打印" prop="flag03">
              <el-select v-model="fatherData.flag03" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in policyPrint"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="首页金额合并打印" prop="flag04">
              <el-select v-model="fatherData.flag04" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in mergePrint"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保额打印" prop="flag05">
              <el-select v-model="fatherData.flag05" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option label="请选择" value=""></el-option>
                <el-option
                    v-for="item in foreheadPrint"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="需求号码" prop="srpisno">
              <el-input v-model="fatherData.srpisno" :readonly="currentOperation_F == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新方式" prop="updateInd">
              <el-select v-model="fatherData.updateInd" :disabled="currentOperation_F == 'view'" placeholder="">
                <el-option
                    v-for="item in updateMode"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="doSave_F" v-if="currentOperation_F != 'view'" class="Defaultbutton">保 存</el-button>
        <el-button @click="mainDialog = false">返 回</el-button>
      </span>
    </el-dialog>

    <!-- 弹框 附档修改-->
    <el-dialog
        :title="title_son"
        :visible.sync="attachedDialog"
        width="60%"
        center>
      <el-form ref="form_S" :model="sonData" :rules="rules_S" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="EUIS主合同" prop="polpln">
              <el-input v-model="sonData.polpln" readonly clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="AS400险种代码" prop="crtable">
              <el-input v-model="sonData.crtable" :readonly="currentOperation_S == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="EUIS产品码" prop="polplnc">
              <el-input v-model="sonData.polplnc" :readonly="currentOperation_S == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="条款打印" prop="flag03">
              <el-select v-model="sonData.flag03" :disabled="currentOperation_S == 'view'" placeholder="">
                <el-option
                    v-for="item in termPrint"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="需求号码" prop="srpisno">
              <el-input v-model="sonData.srpisno" :readonly="currentOperation_S == 'view'" clearable
                        placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新标志" prop="updateInd">
              <el-select v-model="sonData.updateInd" :disabled="currentOperation_S == 'view'" placeholder="">
                <el-option
                    v-for="item in updateMode"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="doSave_S" v-if="currentOperation_S != 'view'" class="Defaultbutton">保 存</el-button>
        <el-button @click="attachedDialog = false">返 回</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import {mapGetters} from 'vuex'
  import constant from '@/utils/constant';
  import {
    addDataForFather, addDataForSon,
    deleteDataForFather, deleteDataForSon, editDataForFather, editDataForSon,
    queryListForFather,
    queryListForSon
  } from "@/api/setting/maintain/insurPolicyPrintMaintenance";
  import validRules from "@/utils/validRules";

  export default {
    data() {
      return {
        mainDialog: false,//默认隐藏 保单打印险种维护主表修改弹框
        attachedDialog: false,//默认隐藏 保单打印险种维护附表修改弹框

        // 查询条件
        rules: {
          polpln: [
            {max: 10, message: '长度在10个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入EUIS险种代码！', trigger: 'blur'}
          ],
          crtable: [
            {max: 4, message: '长度在4个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入AS400险种代码！', trigger: 'blur'}
          ]
        },
        rules_F: {
          polpln: [
            {required: true, message: '请输入EUIS险种代码', trigger: 'blur'},
            {max: 10, message: '长度在10个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入EUIS险种代码！', trigger: 'blur'}
          ],
          crtable: [
            {required: true, message: '请输入AS400险种代码', trigger: 'blur'},
            {max: 4, message: '长度在4个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入AS400险种代码！', trigger: 'blur'}
          ],
          statFund: [],
          flag01: [],
          flag02: [],
          flag03: [],
          flag04: [],
          flag05: [],
          srpisno: [
            {max: 10, message: '长度在10个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入需求号码！', trigger: 'blur'}
          ],
          updateInd: []
        },
        rules_S: {
          polpln: [],
          polplnc: [
            {max: 10, message: '长度在10个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入EUIS产品码！', trigger: 'blur'}
          ],
          crtable: [
            {required: true, message: '请输入AS400险种代码', trigger: 'blur'},
            {max: 4, message: '长度在4个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入AS400险种代码！', trigger: 'blur'}
          ],
          statFund: [],
          flag03: [],
          srpisno: [
            {max: 10, message: '长度在10个字符内', trigger: 'blur'},
            {validator: validRules.isEnglishOrNumber, message: '请正确输入需求号码！', trigger: 'blur'}
          ],
          updateInd: []
        },
        searchParams: {
          polpln: '',
          crtable: ''
        },
        insCodetableData: [],//主档数据
        attachedtableData: [],//附档数据
        loading_F: false,
        loading_S: false,
        isShow_S: false,
        polpln_S: null,//选中的主表EUIS险种代码
        currentOperation_F: 'add',//主表弹框操作类型【add-新增，edit-编辑，view-查看】
        currentOperation_S: 'add',//附表弹框操作类型【add-新增，edit-编辑，view-查看】
        title_father: '保单打印险种维护主表新增',
        title_son: '保单打印险种维护附表新增',

        fatherData: {//主档弹框表单
          polpln: '',
          crtable: '',
          statFund: '',
          flag01: '',
          flag02: '',
          flag03: '',
          flag04: '',
          flag05: '',
          srpisno: '',
          updateInd: '',
          polplnOld: '',
          crtableOld: ''
        },
        sonData: {//附档弹框表单
          polpln: '',
          polplnc: '',
          crtable: '',
          flag01: '',
          flag02: '',
          flag03: '',
          flag04: '',
          flag05: '',
          flag06: '',
          srpisno: '',
          updateInd: '',
          crtableOld: ''
        },
        masterContract: [//主约
          {value: 'M', label: '主约'},
          {value: 'R', label: '附约'}
        ],
        assayType: [//检测类型
          {value: '1', label: '险种搭配'},
          {value: '2', label: '子计划'},
          {value: '3', label: '不检测'}
        ],
        amountType: [//金额类型
          {value: '1', label: '固定'},
          {value: '2', label: '区间'}
        ],
        policyPrint: [//保单条款打印
          {value: '1', label: '同TC02A'},
          {value: '2', label: '参数'}
        ],
        mergePrint: [//首页金额合并打印
          {value: '1', label: '合并'},
          {value: '2', label: '否'}
        ],
        foreheadPrint: [//保额打印
          {value: '1', label: '不打印'},
          {value: '2', label: '打印'}
        ],
        updateMode: [//更新方式
          {value: 'I', label: 'I--新增'},
          {value: 'U', label: 'U--更新'},
          {value: 'D', label: 'D--删除'}
        ],
        termPrint: [//条款打印
          {value: '1', label: '批次打印条款'},
          {value: '2', label: '不打印条款'}
        ],

        //需要给分页组件传的信息
        paginations_F: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 5,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
        },
        paginations_S: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 5,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
        },
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        }
      }
    },
    created() {
      // this.getListForFather();
    },
    mounted() {
      // this.getListForFather();
    },
    methods: {
      //表单格式化函数
      statFundFormat(row) {//主约
        let resString = row.statFund;
        const resArray = this.masterContract.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag01Format(row) {//检测类型
        let resString = row.flag01;
        const resArray = this.assayType.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag02Format(row) {//金额类型
        let resString = row.flag02;
        const resArray = this.amountType.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag03Format(row) {//保单条款打印
        let resString = row.flag03;
        const resArray = this.policyPrint.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag04Format(row) {//首页金额合并打印
        let resString = row.flag04;
        const resArray = this.mergePrint.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag05Format(row) {//保额打印
        let resString = row.flag05;
        const resArray = this.foreheadPrint.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      updateIndFormat(row) {//更新方式
        let resString = row.updateInd;
        const resArray = this.updateMode.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },
      flag03Format_S(row) {//条款打印
        let resString = row.flag03;
        const resArray = this.termPrint.filter(item => {
          return item.value == resString;
        });
        if (resArray.length == 1) {
          resString = resArray[0].label;
        }
        return resString;
      },

      addData_F() {
        this.currentOperation_F = 'add';
        this.title_father = '保单打印险种维护主表新增';
        this.fatherData = {//主档弹框表单
          polpln: '',
          crtable: '',
          statFund: '',
          flag01: '',
          flag02: '',
          flag03: '',
          flag04: '',
          flag05: '',
          srpisno: '',
          updateInd: '',
          polplnOld: '',
          crtableOld: ''
        };
        this.mainDialog = true;
      },
      addData_S() {
        this.currentOperation_S = 'add';
        this.title_son = '保单打印险种维护附表新增';
        if (this.polpln_S) {
          this.sonData = {//附档弹框表单
            polpln: this.polpln_S,
            polplnc: '',
            crtable: '',
            flag01: '',
            flag02: '',
            flag03: '',
            flag04: '',
            flag05: '',
            flag06: '',
            srpisno: '',
            updateInd: '',
            crtableOld: ''
          };
          this.attachedDialog = true;
        } else {
          this.$message({
            type: 'info',
            message: '请选中主档一条数据'
          });
        }
      },
      editData_F(item) {
        this.currentOperation_F = 'edit';
        this.title_father = '保单打印险种维护主表修改';
        item.polplnOld = item.polpln;
        item.crtableOld = item.crtable;
        for (const key in this.fatherData) {
          if (item[key]) {
            this.fatherData[key] = item[key];
          } else {
            this.fatherData[key] = '';
          }
        }
        this.mainDialog = true;
      },
      editData_S(item) {
        this.currentOperation_S = 'edit';
        this.title_son = '保单打印险种维护附表修改';
        item.crtableOld = item.crtable;
        for (const key in this.sonData) {
          if (item[key]) {
            this.sonData[key] = item[key];
          } else {
            this.sonData[key] = '';
          }
        }
        this.attachedDialog = true;
      },
      deleteData_F(item) {
        this.$confirm("将同步删除其对应的附表数据，确认删除？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('loading/CHANGE_LOADING', true)
          deleteDataForFather(item).then(res => {
            this.$store.dispatch('loading/CHANGE_LOADING', false)
            if (res.resultCode == constant.SUCCESS) {
              this.$message({
                type: 'success',
                message: res.resultMsg
              });
              this.getListForFather();
            }
          }).catch(err => {
            this.$store.dispatch('loading/CHANGE_LOADING', false);
          })
        });
      },
      deleteData_S(item) {
        this.$confirm("确认删除？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('loading/CHANGE_LOADING', true)
          deleteDataForSon(item).then(res => {
            this.$store.dispatch('loading/CHANGE_LOADING', false)
            if (res.resultCode == constant.SUCCESS) {
              this.$message({
                type: 'success',
                message: res.resultMsg
              });
              this.paginations_S.pageIndex = 1;
              this.getListForSon();
            }
          }).catch(err => {
            this.$store.dispatch('loading/CHANGE_LOADING', false);
          })
        });
      },
      doSave_F() {
        this.$refs['form_F'].validate((valid) => {
          if (valid) {
            if (this.currentOperation_F == 'add') {
              this.$store.dispatch('loading/CHANGE_LOADING', true);
              addDataForFather(this.fatherData).then(res => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
                if (res.resultCode == constant.SUCCESS) {
                  this.mainDialog = false;
                  this.$message({
                    type: 'success',
                    message: '新增主档成功！'
                  });
                  this.searchParams.polpln = this.fatherData.polpln;
                  this.subGetList();
                }
              }).catch(err => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
              });
            } else if (this.currentOperation_F == 'edit') {
              this.$store.dispatch('loading/CHANGE_LOADING', true);
              editDataForFather(this.fatherData).then(res => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
                if (res.resultCode == constant.SUCCESS) {
                  this.mainDialog = false;
                  this.$message({
                    type: 'success',
                    message: '修改主档成功！'
                  });
                  this.searchParams.polpln = this.fatherData.polpln;
                  this.subGetList();
                }
              }).catch(err => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
              });
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      doSave_S() {
        this.$refs['form_S'].validate((valid) => {
          if (valid) {
            if (this.currentOperation_S == 'add') {
              this.$store.dispatch('loading/CHANGE_LOADING', true);
              addDataForSon(this.sonData).then(res => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
                if (res.resultCode == constant.SUCCESS) {
                  this.attachedDialog = false;
                  this.$message({
                    type: 'success',
                    message: '新增附档成功！'
                  });
                  this.getListForSon();
                }
              }).catch(err => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
              });
            } else if (this.currentOperation_S == 'edit') {
              this.$store.dispatch('loading/CHANGE_LOADING', true);
              editDataForSon(this.sonData).then(res => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
                if (res.resultCode == constant.SUCCESS) {
                  this.attachedDialog = false;
                  this.$message({
                    type: 'success',
                    message: '修改附档成功！'
                  });
                  this.getListForSon();
                }
              }).catch(err => {
                this.$store.dispatch('loading/CHANGE_LOADING', false);
              });
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      // 查询主列表
      getListForFather() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.isShow_S = false;
            this.paginations_F.total = 0;
            this.insCodetableData = [];
            const para = {
              "polpln": this.searchParams.polpln,
              "crtable": this.searchParams.crtable,
              "pageSize": this.paginations_F.pageSize,
              "pageNumber": this.paginations_F.pageIndex,
            };
            this.$store.dispatch('loading/CHANGE_LOADING', true);
            queryListForFather(para).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
              if (res.resultCode == constant.SUCCESS) {
                if (res.data && res.data.rows.length) {
                  this.paginations_F.total = res.data.total;
                  this.insCodetableData = res.data.rows;
                } else {
                  this.$message({
                    message: '无符合条件资料',
                    type: 'error'
                  });
                }
              }
            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        });
      },
      // 查询附列表
      getListForSon() {
        this.isShow_S = true;
        this.paginations_S.total = 0;
        this.attachedtableData = [];
        const para = {
          "polpln": this.polpln_S,
          "pageSize": this.paginations_S.pageSize,
          "pageNumber": this.paginations_S.pageIndex,
        };
        this.$store.dispatch('loading/CHANGE_LOADING', true);
        queryListForSon(para).then(res => {
          this.$store.dispatch('loading/CHANGE_LOADING', false);
          if (res.resultCode == constant.SUCCESS) {
            if (res.data && res.data.rows.length) {
              this.paginations_S.total = res.data.total;
              this.attachedtableData = res.data.rows;
            }
          }
        }).catch(err => {
          this.$store.dispatch('loading/CHANGE_LOADING', false);
        })
      },
      // 选中主表一行，显示其对应附表table
      selectRow_F(item) {
        if (item) {
          this.polpln_S = item.polpln;
          this.paginations_S.pageIndex = 1;
          this.getListForSon();
        }
      },
      // 双击主表一行，显示详情
      viewRow_F(item) {
        this.currentOperation_F = 'view';
        this.title_father = '保单打印险种维护主表查看';
        this.fatherData = item;
        this.mainDialog = true;
      },
      // 双击主表一行，显示详情
      viewRow_S(item) {
        this.currentOperation_S = 'view';
        this.title_son = '保单打印险种维护附表查看';
        this.sonData = item;
        this.attachedDialog = true;
      },
      // 每页多少条切换
      handleSizeChange_F(pageSize) {
        this.paginations_F.pageSize = pageSize;
        this.getListForFather();
      },
      // 上下分页
      handleCurrentChange_F(page) {
        this.paginations_F.pageIndex = page;
        this.getListForFather();
      },
      // 每页多少条切换
      handleSizeChange_S(pageSize) {
        this.paginations_S.pageSize = pageSize;
        this.getListForSon();
      },
      // 上下分页
      handleCurrentChange_S(page) {
        this.paginations_S.pageIndex = page;
        this.getListForSon();
      },
      // 根据条件查询列表
      subGetList() {
        this.paginations_F.pageIndex = 1;
        this.getListForFather();
      },
      // 清除查询条件
      resetSearch() {
        this.searchParams.polpln = '';
        this.searchParams.crtable = '';
      }
    },
    computed: {
      ...mapGetters(['tags']),
      reload() {
        return this.$store.state.loading.reload;
      }
    },
    activated() {
      if (this.reload) {
        this.$store.dispatch('loading/CHNAGE_RELOAD', false);
        Object.assign(this.$data, this.$options.data());
      }
    }
  }
</script>

<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }

  .operationIcon {
    // padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 0 3px #f9f9f9;
  }

  .search_container {
    padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
  }

  .common-box {
    padding-bottom: 15px;
  }

  .common-lab {
    line-height: normal !important;
    text-align: right;

    .labelName {
      text-align: right;
    }
  }
</style>



